import React, { Component, Fragment } from 'react';
import styles from '../index.less';
import { Tabs } from 'antd';
import Tablecontent from './Tablecontent';
import { getShopId } from '@/utils/localStorage';
import { connect } from 'dva';
function keyValue(key) {
    if (key == 1) {
        return ''
    }
    else if (key == 2) {
        return 'WAIT_PAY'
    }
    else if (key == 3) {
        return 'FINISH'
    }
}
@connect(({ buyoutes }) => ({ buyoutes }))
export default class Tablelist extends Component {
    state = {
        value: 1,
        tabsValue: 1
    }
    callback = (key) => {
        this.setState({
            tabsValue: key
        })
        const { formData } = this.props;
        if (!!formData) {
            this.inForinmation(formData, keyValue(key));
        }
        else {
            this.onRequest(keyValue(key));
        }
    }
    onRequest = (status) => {
        const { dispatch } = this.props;
        dispatch({
            type: 'buyoutes/getTableList',
            payload: {
                addressUserName: "",
                addressUserPhone: "",
                buyOutOrderId: "",
                createTimeEnd: "",
                createTimeStart: "",
                orderId: "",
                pageNumber: 1,
                pageSize: 10,
                productId: "",
                productName: "",
                rentTimeEnd: "",
                rentTimeStart: "",
                status: status,
                telephone: "",
                userName: "",
                shopId: getShopId(),
            }
        })
    }
    inForinmation = (values, status) => {
        const {
            orderbianhao,//订单编号
            goodsName, //商品名称
            orderid,//商品ID
            orderstate, //订单状态
            olOrderid, //原订单编号
            pleaseOrderName,//下单人姓名
            pleaseOrderPhone, //下单人手机号
            goodsPeopleName,//收货人姓名
            goodsPhone, //收货人手机号
            rentTime,//起租时间
            createTime //创建时间
        } = values;
        const { dispatch } = this.props;
        dispatch({
            type: 'buyoutes/getTableList',
            payload: {
                addressUserName: !!goodsPeopleName ? goodsPeopleName : '',
                addressUserPhone: !!goodsPhone ? goodsPhone : '',
                buyOutOrderId: !!orderbianhao ? orderbianhao : '',
                createTimeEnd: !!createTime ? moment(createTime[1]).format('YYYY-MM-DD') : '',
                createTimeStart: !!createTime ? moment(createTime[0]).format('YYYY-MM-DD') : '',
                orderId: !!olOrderid ? olOrderid : '',
                pageNumber: 1,
                pageSize: 10,
                productId: !!orderid ? orderid : '',
                productName: !!goodsName ? goodsName : '',
                rentTimeEnd: !!rentTime ? moment(rentTime[1]).format('YYYY-MM-DD') : '',
                rentTimeStart: !!rentTime ? moment(rentTime[0]).format('YYYY-MM-DD') : '',
                status: status,
                telephone: !!pleaseOrderPhone ? pleaseOrderPhone : '',
                userName: !!pleaseOrderName ? pleaseOrderName : '',
                shopId: getShopId(),
            }
        })
    }
    render() {
        const { TabPane } = Tabs;
        const { value, tabsValue, formData } = this.state;
        return (
            <Fragment>
                <Tabs
                    defaultActiveKey={`${value}`}
                    onChange={this.callback}>
                    <TabPane tab="全部" key="1">
                        <Tablecontent formData={formData} typeOrder={tabsValue} />
                    </TabPane>
                    <TabPane tab="待支付" key="2">
                        <Tablecontent formData={formData} typeOrder={tabsValue} />
                    </TabPane>
                    <TabPane tab="订单完成" key="3">
                        <Tablecontent formData={formData} typeOrder={tabsValue} />
                    </TabPane>
                </Tabs>
            </Fragment>
        )
    }
} 